package com.aplink.generic.util.objectrule;

import java.io.Serializable;
import java.util.ArrayList;

import com.aplink.generic.constant.type.EnableConditionType;
import com.aplink.generic.pojo.GenericObject;

public class EnableCondition implements Serializable {
    private static final long serialVersionUID = -1903422842097429031L;
	private EnableConditionType mInvalidType;
	private ArrayList<Rule> mRules;
	private String mType;
	private EnableConditionType mValidType;

	public EnableConditionType getInvalidType() {
		return this.mInvalidType;
	}

	public ArrayList<Rule> getRules() {
		return this.mRules;
	}

	public String getType() {
		return this.mType;
	}

	public EnableConditionType getValidType() {
		return this.mValidType;
	}

	public boolean isValid(final GenericObject genericObject) {
		if (this.mType.equalsIgnoreCase("AND")) {
			boolean result = true;
			for (final Rule rule : this.mRules) {
				result = result && rule.isValid(genericObject);
			}
			if (result) {
				return true;
			}
		} else {
			boolean result = false;
			for (final Rule rule : this.mRules) {
				result = result || rule.isValid(genericObject);
			}
			if (result) {
				return true;
			}
		}
		return false;
	}

	public void setInvalidType(final EnableConditionType invalidType) {
		this.mInvalidType = invalidType;
	}

	public void setRules(final ArrayList<Rule> rules) {
		this.mRules = rules;
	}

	public void setType(final String type) {
		this.mType = type;
	}

	public void setValidType(final EnableConditionType enableConditionType) {
		this.mValidType = enableConditionType;
	}
}
